import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

class ListViewSeparatedLn extends StatefulWidget {
  const ListViewSeparatedLn({super.key});

  @override
  State<ListViewSeparatedLn> createState() => _ListViewSeparatedLnState();
}

class _ListViewSeparatedLnState extends State<ListViewSeparatedLn> {
  @override
  Widget build(BuildContext context) {
    //下划线widget预定义以供复用。
    Widget divider1 = Divider(
      color: Colors.blue,
    );
    Widget divider2 = Divider(color: Colors.green);
    return Scaffold(
        appBar: AppBar(
          title: Text(
            "ListView", // 设置标题文本
            style: TextStyle(
              color: Colors.white, // 设置标题字体颜色
            ),
          ),
          iconTheme: IconThemeData(
            color: Colors.white, // 设置返回图标颜色
          ),
          backgroundColor: Colors.deepPurple, // 设置AppBar背景颜色
        ),
        body: ListView.separated(
          itemCount: 100,
          //列表项构造器
          itemBuilder: (BuildContext context, int index) {
            return ListTile(title: Text("$index"));
          },
          //分割器构造器
          separatorBuilder: (BuildContext context, int index) {
            return index % 2 == 0 ? divider1 : divider2;
          },
        ));
  }
}
